import { AskTypes } from "redux/constants";

export const Creators = {
  // 问题列表
  listRequest: ({ page, limit }) => ({
    type: AskTypes.QUESTION_LIST_REQUEST,
    payload: { page, limit },
  }),
  listSuccess: (data) => ({
    type: AskTypes.QUESTION_LIST_SUCCESS,
    payload: data,
  }),
  listFailure: (error) => ({
    type: AskTypes.QUESTION_LIST_FAILURE,
    payload: error,
  }),
  // 问题详情
  detailRequest: (sn) => ({
    type: AskTypes.QUESTION_DETAIL_REQUEST,
    payload: sn,
  }),
  detailSuccess: (data) => ({
    type: AskTypes.QUESTION_DETAIL_SUCCESS,
    payload: data,
  }),
  detailFailure: (error) => ({
    type: AskTypes.QUESTION_DETAIL_FAILURE,
    payload: error,
  }),
  // 发布问题
  publishRequest: ({ token, title, content }) => ({
    type: AskTypes.QUESTION_PUBLISH_REQUEST,
    payload: { token, title, content },
  }),
  publishSuccess: (data) => ({
    type: AskTypes.QUESTION_PUBLISH_SUCCESS,
    payload: data,
  }),
  publishFailure: (error) => ({
    type: AskTypes.QUESTION_PUBLISH_FAILURE,
    payload: error,
  }),
  // 编辑问题
  editRequest: ({ token, ask_id, values }) => ({
    type: AskTypes.QUESTION_EDIT_REQUEST,
    payload: { token, ask_id, values },
  }),
  editSuccess: (data) => ({
    type: AskTypes.QUESTION_EDIT_SUCCESS,
    payload: data,
  }),
  editFailure: (error) => ({
    type: AskTypes.QUESTION_EDIT_FAILURE,
    payload: error,
  }),
};
